﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ent;
namespace DAL
{
    public class MonHocDAL:clsKetNoi 
    {
        dataDataContext dt;
        public List<MonHocTbl> LayMonHoc_MaDethi(string mssv)
        {
            dt = GetKetnoi();
            IEnumerable<MONHOC> q = (from i in dt.MONHOCs
                                     join u in dt.CHUONGs on i.MAMONHOC equals u.MAMONHOC
                                     join j in dt.CAUHOIs on u.MACHUONG equals j.MACHUONG
                                     join z in dt.CHITIETDETHIs on j.MACAUHOI equals z.MACAUHOI
                                     join x in dt.DETHIs on z.MADETHI equals x.MADETHI
                                     join y in dt.DIEMs on x.MADETHI equals y.MADETHI
                                     where y.MSSV == mssv
                                     select i).Distinct();
            List<MonHocTbl> ds = new List<MonHocTbl>();
            foreach (MONHOC item in q)
            {
                MonHocTbl mh = new MonHocTbl();
                mh.MaMonHoc = item.MAMONHOC;
                mh.TenMonHoc = item.TENMONHOC;
                ds.Add(mh);
            }
            return ds;
        }
        public MonHocTbl LayMonHoc_TheoMaDethi(string made)
        {
            dt = GetKetnoi();
            MONHOC q = (from i in dt.MONHOCs
                        join u in dt.CHUONGs on i.MAMONHOC equals u.MAMONHOC
                        join j in dt.CAUHOIs on u.MACHUONG equals j.MACHUONG
                        join z in dt.CHITIETDETHIs on j.MACAUHOI equals z.MACAUHOI
                        join x in dt.DETHIs on z.MADETHI equals x.MADETHI
                        where x.MADETHI == made
                        select i).Distinct().Single();
            MonHocTbl mh = new MonHocTbl();
            mh.MaMonHoc = q.MAMONHOC;
            mh.TenMonHoc = q.TENMONHOC;

            return mh;
        }
    }
}
